package com.neusoft.controller;

import com.neusoft.base.BaseController;
import com.neusoft.model.OrderSearch;
import com.neusoft.po.CarItemRel;
import com.neusoft.service.CarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 购物车请求控制器
 *
 * @author Lucifer
 * @since 2021/5/16 8:47
 */
@RestController
@RequestMapping("/car")
@Api(tags = "购物车接口")
public class CarController extends BaseController {

    @Resource
    private CarService carService;

    @PostMapping("/page")
    @ApiOperation("购物车下的所有商品")
    public Object get(@RequestBody OrderSearch orderSearch) {
        return carService.page(orderSearch);
    }

    @PostMapping
    @ApiOperation("添加商品到购物车")
    public Integer save(@RequestBody CarItemRel carItemRel) {
        carService.save(carItemRel);
        return carItemRel.getId();
    }

    @DeleteMapping("/remove")
    @ApiOperation("删除（新增，修改同）")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商品ID集合", name = "ids", required = true),
            @ApiImplicitParam(value = "用户ID", name = "user_id", required = true),
    })
    public void delete(Integer[] ids, Integer user_id) {
        carService.remove(ids, user_id);
    }

}
